<!-- 品牌管理 -->
<template>
    <div>
        
        <div class="table-page-search-wrapper">
            <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                    <a-form-item label="用户ID">
                            <a-input v-model="userId" allow-clear placeholder="请输入用户ID" />
                        </a-form-item>
                    <!-- <a-form-item label="用户ID">
                        <a-input   v-model="dataList.userId" placeholder="请输入用户ID进行查询"  readonly="readonly" allow-clear></a-input>
                    </a-form-item> -->
                     <a-form-item label="结束时间">
                        <a-input   style="width:260px" v-model="dataList.endDate" placeholder="请输入用户ID进行查询"  readonly="readonly" allow-clear></a-input>
                    </a-form-item>
                     <a-form-item label="是否可用">
                        <a-radio-group v-model="dataList.isActive" >
                            <a-radio  v-for="(item,i) in isHideList" :key="i" :value="item.id">{{item.name}}</a-radio>
                        </a-radio-group>
                    </a-form-item>
                   
                    <a-form-item label="是否开启自动功能">
                        <a-radio-group v-model="dataList.isAutoSendRedPacket" >
                            <a-radio  v-for="(item,i) in isHideList" :key="i" :value="item.id">{{item.name}}</a-radio>
                        </a-radio-group>
                    </a-form-item>
                   <a-form-item v-bind="formItemLayoutWithOutLabel">
                            <a-button type="primary" @click="getData()">查询</a-button>
                        </a-form-item>
                </a-form>
        </div>
        <!-- <a-table size="small" rowKey="id" :loading="isload" :columns="columns" :data-source="dataList">
            
                 <template slot="isOn" slot-scope="text, record">
                       <a-switch checked-children="是" un-checked-children="否" disabled :checked="record.isOn == '1' ? true : false" />
               </template>
            <template slot="operation" slot-scope="text, record">
                
                <div class="editable-row-operations">
                    <a-button type="link" @click="update(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前数据?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button type="link">删除</a-button>
                    </a-popconfirm>
                </div>
            </template>
        </a-table> -->

        <a-modal
            title="添加、修改设置"
            :visible="visible"
            @ok="handleOk"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                   
                     <a-form-item label="产品名称">
                        <a-input   v-model="item.productName" placeholder="请输入产品名称" allow-clear></a-input>
                    </a-form-item>
                     <a-form-item label="可用天数">
                        <a-input   v-model="item.activeDay" placeholder="请输入可用天数" allow-clear></a-input>
                    </a-form-item>
                     <a-form-item label="优惠前价格">
                        <a-input   v-model="item.price" placeholder="请输入优惠前价格" allow-clear></a-input>
                    </a-form-item>
                     <a-form-item label="当前价格">
                        <a-input   v-model="item.realPrice" placeholder="请输入当前价格" allow-clear></a-input>
                    </a-form-item>
                     <a-form-item label="是否开启">
                        <a-radio-group v-model="item.isOn" >
                            <a-radio  v-for="(item,i) in isHideList" :key="i" :value="item.id">{{item.name}}</a-radio>
                        </a-radio-group>
                    </a-form-item>
                   
                </a-form>
            </div>
        </a-modal>
    </div>
</template>

<script>
import { queryVipUser  } from '@/api/vip';
import { columns } from './table';
import moment from "moment";
export default {
    data () {
        return {
             brandId: this.global.brandId,
            dataList: {
                userId:"",
                endDate:"",
                isActive:0,
                isAutoSendRedPacket:0
            },
            total: 0,
            size: 10,
            page: 1,
            columns,
            isload: false,
            visible: false,
            item: {
                id: '',
                productName:"",//名称	
                activeDay:"",//可用天数	
                price:"",//优惠前价格		
                realPrice:"",//当前价格				
                isOn:1,//是否开启,0:否,1:是	
            },
            isHideList: [
                { id:1, name: '是'},
                { id: 0, name: '否'},
            ],
            grade: undefined,
            gradeList: [],
               previewImgVisible: false,
               userId:"",
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
        };
    },
     async created(){
        try {
            // this.getAllData()
        } catch (error) {
            this.$notification['error']({
                message: '提示',
                description: '网路丢失，请稍后再试！',
                duration: 8,
            })
        }
    },
   
    methods: {
        moment,
         async getAllData(){
            try {
                    this.getData()
                } catch (error) {
                    this.$notification['error']({
                        message: '提示',
                        description: '网路丢失，请稍后再试！',
                        duration: 8,
                    })
                }
        },
        getData(){
            let _this = this
            _this.isload = true
            if(_this.userId==''){
               _this.$message.warning('请先输入用户Id!')
                return  
            }
            const params = {
                'brandId':_this.brandId,
                'userId':_this.userId,
            }
            queryVipUser(params)
            .then(res=>{
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 添加
        add(){

            this.item={
                id: '',
                productName:"",//名称	
                activeDay:"",//可用天数	
                price:"",//优惠前价格		
                realPrice:"",//当前价格				
                isOn:1,//是否开启,0:否,1:是
            },
            this.visible = true
        },
        // 修改
        update(item){
            this.item = JSON.parse(JSON.stringify(item))
          this.visible = true
          
        },
        // 确定添加、删除
        handleOk(){
          
            let _this = this
            const params = {
                'id':_this.item.id,
                'brandId':_this.brandId,
                'productName':_this.item.productName,
                'activeDay':_this.item.activeDay,
                'price':_this.item.price,
                'realPrice':_this.item.realPrice,
                'isOn':_this.item.status,
            }
            if(!_this.brandId){
                this.$message.warning('请先选择品牌!')
                return
            }
            if(_this.item.productName===''){
                this.$message.warning('请先输入名称!')
                return
            }
             if(_this.item.activeDay===''){
                this.$message.warning('请先输入可用天数!')
                return
            }
            if(_this.item.price<0){
                this.$message.warning('请先输入优惠前价格!')
                return
            }
             if(_this.item.realPrice<0){
                this.$message.warning('请先输入当前价格!')
                return
            }
            updateVipProduct(params)
            .then(res=>{
                if(res.success){
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.item.id ? '修改成功' : '添加成功',
                        duration: 8,
                    })
                    _this.visible = false
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除
        del(item){
            let _this = this
            const params = {
                'id':item.id,
                'isDelete':1,
            }
            updateVipProduct(params)
            .then(res=>{
                if(res.success){
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>